/**
 * 2025/01/01 - 2025/12/31
 */
package com.snail.server.database.engine.ddl.index.enums;

import com.baomidou.mybatisplus.annotation.IEnum;
import com.snail.starter.commons.exception.BizException;
import com.snail.server.database.engine.error.DatabaseEngineErrorCode;
import lombok.Getter;
import lombok.ToString;

import java.util.Arrays;

/**
 *
 * @author zgadmin
 * @date 2025/8/28 16:32
 *
 */
@Getter
@ToString
public enum IndexFieldOrderByEnum implements IEnum<String> {

    ASC("ASC", "升序"),
    DESC("DESC", "降序"),
    ;

    private final String value;

    private final String desc;

    IndexFieldOrderByEnum(String value, String desc){
        this.value = value;
        this.desc = desc;
    }

    public static IndexFieldOrderByEnum getEnum(String value) {
        if(null == value || "".equals(value)){
            return ASC;
        }
        return Arrays.stream(values()).filter(e -> e.getValue().equalsIgnoreCase(value)).findFirst().orElseThrow(() -> BizException.of(DatabaseEngineErrorCode.NOT_SUPPORT_INDEX_FIELD_ORDER_BY, new Object[]{value}));
    }
}